package com.fuershiye.woman.monitor.service.impl;

import java.util.List;
import java.util.Set;

import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fuershiye.woman.monitor.beans.IdName;
import com.fuershiye.woman.monitor.beans.Page;
import com.fuershiye.woman.monitor.dao.FormsDepartDao;
import com.fuershiye.woman.monitor.model.FormsDepart;
import com.fuershiye.woman.monitor.service.FormsDepartService;
import com.google.common.collect.Lists;

@Service("formsDepartService")
public class FormsDepartServiceImpl implements FormsDepartService {

	@Autowired
	private FormsDepartDao itDao;

	@Override
	public void save(FormsDepart it) {
		itDao.save(it);
	}

	@Override
	public void delete(Long id) {
		itDao.delete(id);
	}

	@Override
	public FormsDepart get(Long id) {
		return itDao.get(id);
	}

//	/**
//	 * 取当前表中最大数据
//	 *
//	 * @return
//	 */
//	@Override
//	public FormsDepart getTop() {
//		return itDao.getTop();
//	}

//	/**
//	 * @param sort
//	 *            sort(当前位置)
//	 * @param aim
//	 *            方向 (1:比id大的; 2:比id小的)
//	 * @param count
//	 *            取几条数据
//	 * @return
//	 */
//	@Override
//	public FormsDepart findBySort(Long sort, Integer aim, Integer count) {
//		return itDao.findBySort(sort,aim,count);
//	}
	
//	@Override
//	public List<IdName> getIdNameByDepart(Long depart, Integer year, Long forms) {
//		return itDao.getIdNameByDepart(depart, year, forms);
//	}
	
	@Override
	public FormsDepart findExist(Long departid, Long formsid, Integer year) {
		return itDao.findByCondtion(null, departid, formsid, year, null);
	}
	
	@Override
	public FormsDepart findByDepartYearForms(Long departid, Integer year, Long formsid) {
		return itDao.findByCondtion(null, departid, formsid, year, null);
	}

//	@Override
//	public List<FormsDepart> listByCondtion(Long formid, Long areaid, Integer year, Integer status, Page page) {
//		List<Long> areaids = Lists.newArrayList();
//		areaids.add(areaid);
//		List<Integer> years = Lists.newArrayList();
//		years.add(year);
//		return itDao.listByCondtion(areaids, null, years, formid, status, page);
//	}
	
//	@Override
//	public List<FormsDepart> listByCondtion(List<Long> departids, Integer year, Long formsid, Integer status, Page page) {
//		List<Integer> years = Lists.newArrayList();
//		years.add(year);
//		return itDao.listByCondtion(null, departids, years, formsid, status, page);
//	}

//	@Override
//	public List<FormsDepart> listByCondtion(Long departid, List<Integer> years, Long formsid, Integer status, Page page) {
//		List<Long> departids = Lists.newArrayList();
//		departids.add(departid);
//		return itDao.listByCondtion(null, departids, years, formsid, status, page);
//	}

	@Override
	public List<FormsDepart> listByCondtionStatusOpposite(List<Long> departids, List<Integer> years, Long formsid, Integer status, Page page) {
		return itDao.listByCondtionStatusOpposite(null, departids, years, formsid, status, page);
	}

	@Override
	public List<FormsDepart> listByCondtionStatusOppositeAreaid(Long areaid, List<Integer> years, Long formsid, Integer status, Page page) {
		List<Long> areaids = Lists.newArrayList();
		areaids.add(areaid);
		return itDao.listByCondtionStatusOpposite(areaids, null, years, formsid, status, page);
	}

	@Override
	public List<FormsDepart> listInCondtionStatusOpposite(List<Long> departids, List<Integer> years, Long formsid, Integer status, Page page){
		return itDao.listByCondtionStatusOpposite(null, departids, years, formsid, status, page);
	}

//	@Override
//	public int countByCondtionStatusOpposite(Long departid, List<Integer> years, Long formsid, Integer status) {
//		List<Long> departids = Lists.newArrayList();
//		departids.add(departid);
//		return itDao.countByCondtionStatusOpposite(null, departids, years, formsid, status);
//	}

	@Override
	public int countByCondtionStatusOppositeAreaid(Long areaid, Long formsid, Integer year, Integer status) {
		List<Long> areaids = Lists.newArrayList();
		areaids.add(areaid);
		List<Integer> years = Lists.newArrayList();
		years.add(year);
		return itDao.countByCondtionStatusOpposite(areaids, null, years, formsid, status);
	}

	@Override
	public List<FormsDepart> listByCondtion(List<Long> departids, List<Integer> years, Long formsid, Integer status, Page page) {
		return itDao.listByCondtion(null, departids, years, formsid, status, page);
	}
	
//	@Override
//	public int countByCondtion(Long areaid, Long departid, Long formsid, Integer year, Integer status) {
//		List<Long> areaids = Lists.newArrayList();
//		areaids.add(areaid);
//		List<Long> departids = Lists.newArrayList();
//		departids.add(departid);
//		List<Integer> years = Lists.newArrayList();
//		years.add(year);
//		return itDao.countByCondtion(areaids, departids, years, formsid, status);
//	}
	@Override
	public int countByCondtion(List<Long> departids, Integer year, Long forms) {
		List<Integer> years = Lists.newArrayList();
		years.add(year);
		return itDao.countByCondtion(null, departids, years, forms, null);
	}
	@Override
	public List<Integer> getYears(List<FormsDepart> formsDepartList) {
		List<Integer> result = Lists.newArrayList();

		Set<Integer> years = Sets.newHashSet();
		for (FormsDepart formsDepart : formsDepartList) {
			if(formsDepart!=null && formsDepart.getYear()!=null){
				years.add(formsDepart.getYear());
			}
		}

		result.addAll(years);
		return result;
	}

}
